package dfbz.homework10;

public class Task {
    private Person person;
    private int index = 1;

    public Task(Person person) {
        this.person = person;
    }

    public void test01(String name, String sex) {
            synchronized (this) {
                while (index != 1) {
                    try {
                        this.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                person.setName(name);
                person.setSex(sex);
                System.out.println("赋值->姓名:" + name + "，性别:" + sex);
                index = 2;
                this.notify();
            }
        }

    public void task2() {
            synchronized (this) {
                while (index != 2) {
                    try {
                        this.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("打印->姓名:" + person.getName() + "，性别:" + person.getSex());
                index = 1;
                this.notify();
            }
        }
    }

